<template>
	<view class="body ">
		<view class="head">
			<view class="head_left" @click="back"><image src="/static/img/fanhui.png" ></image></view>
			<view class="head_center hei_38_bold">个人信息</view>
			<view class="head_right hei_30"> </view>
		</view>
		<view class="content">
			<view class="app_content">
				<view class="ziliao hei_30">
					<view class="ziliao_list"  @click="up_zheng">
						<text>头像</text>
						<view>
							<image  class="leftdiv" :src="touxiang"></image>
							<image src="/static/img/go_right.png" class="go"></image>
						</view>
					</view>
					<view class="ziliao_list" >
						<text>手机号码</text>
						<view class="hui_30">{{user.username}}</view>
					</view>
					

					<view class="ziliao_list" >
						<text>注册时间</text>
						<view class="hui_30">{{user.created_at}}</view>
					</view>
				</view>

				<view class="ziliao hei_30 border_top">
					<navigator url="/pages/index/change_password" class="ziliao_list">
						<text>修改密码</text>
						<view class="hui_30"><image src="/zu/static/img/go_right.png" class="go"></image></view>
					</navigator>
                  <!-- <navigator url="/pages/index/yinsi" class="ziliao_list">
						<text>隐私政策</text>
						<view class="hui_30"><image src="/zu/static/img/go_right.png" class="go"></image></view>
				
					</navigator>
					<navigator url="/pages/index/xieyi" class="ziliao_list">
						<text>用户协议</text>
						<view class="hui_30"><image src="/zu/static/img/go_right.png" class="go"></image></view>
					</navigator> -->
					<!-- <view class="ziliao_list" @click="go_zhuxiao">
						<text>注销账号</text>
						<view class="hui_30"><image src="/zu/static/img/go_right.png" class="go"></image></view>
					</view> -->
				</view>
				<view class="tuichu hei_30" @click="logout()">退出当前账号</view>
				
				<view class="banquan qian_28">
					<view class="">
						Copyright © 2010-2025
						
					</view>
					<view class="">
						xxx版权所有
					</view>
					<!-- <u-parse :content="replace_em(zhanbeian)"></u-parse> -->
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	//#ifdef H5
		   import $ from '@/common/jquery-3.4.1.min.js';
	//#endif
	import uParse from '@/components/feng-parse/parse.vue';
export default {
	data() {
		return {
			img_url: uni.getStorageSync('img_url'),
			touxiang:'',
			userid:'',
			user:'',
			qq:'',
			tongzhi_phone:'',
			zhanbeian:''
		};
	},
components: {
		
		uParse
	},
	onShow() {},
	onLoad(option) {

		this.get_user()
		
	},
	methods: {
		back() {
			uni.navigateBack();
		},
		get_user() {
			this.$http
				.get({
					url: '/api/getUserInfo',
					data:{
						none_load:true,
					}
				})
				.then(res => {
					if (res.code == 200) {
						if (res.user) {
							this.is_login=true
							this.user = res.user;
							this.touxiang=res.user.avatar_url
							
						} else {
							this.is_login=false
						}
					}
				});
		},
		replace_em(str) {
			str = str.replace(/&amp;/g, "");
			str = str.replace(/&nbsp;/g, "");
			str = str.replace(/nbsp;/g, "");
			str = str.replace(/\</g, '&lt;');
			str = str.replace(/\>/g, '&gt;');
			str = str.replace(/\n/g, '<br/>');
			str = str.replace(/\[em_([0-9]*)\]/g, '<img src="https://imgxh.hongvv.com/zu/static/bkhumor-emoji/$1.gif" border="0" style="width:40rpx;height:40rpx"/></img>');
			return str;
		},
		get_peizhi(){
			var data={
				none_load:true,
			}
			var arry=[
				'zhanbeian'
				]
			arry.forEach(function(item, index) {
				data['peizhi[' + index + ']'] = item;
			});
			
			this.$http
				.post({
					url: '/mapi/index/findpeizhi',
					data:data
				})
				.then(res => {
					if (res.code == 0) {
						
						this.zhanbeian=res.data.zhanbeian
					}
				});
		},
		up_zheng() {
			let that = this;
	
			const itemList = [
							'从相册中选择', 
							'拍照']
						const sizeType = ['original', 'compressed']
						const source = ['album', 'camera']  
						const success = ({tempFilePaths:a, tempFiles: b}) => {
							console.log('tempFiles', b[0].path)
							// var img=  a ? a[0] : b[0].path
							// console.log(a)
							that.up_photo(b[0]);
							
							
						};
						uni.showActionSheet({
							itemList,
							success: ({tapIndex: i}) => {
									uni.chooseImage({
										count: 1,
										sizeType,
										sourceType: [source[i]],
										success
									});
							},
							fail() {
								that.$refs.popup_quanxian.close();
							}
						})
			
		},
		up_photo(img){
			var self = this;
					//#ifdef H5
						var formdata = new FormData(); // 创建一个form类型的数据
						formdata.append("file",img); // 获取上传文件的数据
						console.log(formdata)
						$.ajax({
						  url:this.$http.baseUrl+'/api/upload',
						  type: "post",
						  async: true,
						  dataType:"json",
						  data: formdata,
						  cache: false,			//上传文件无需缓存
						  processData: false,		//用于对data参数进行序列化处理 这里必须false
						  contentType: false, 
						  success: function(ret) {
								
								self.touxiang=ret.fileUrl
								 self.upimg()
						  },
						  error: function(err) {
								console.log(err)
							alert('上传失败')
						  }
						});		
						//#endif	
						// #ifdef MP-WEIXIN
						uni.uploadFile({
							name: "file",    //文件上传的name值
							url:this.$http.baseUrl+'/api/upload',
							header:{
								'referer':self.$http.baseUrl
							},
							formData:{
								
							},   //上传额外携带的参数
							filePath: img.path,     //临时路径
							fileType: "image",               //文件类型
							success: (ret) => {
							  console.log(ret,'retret')
							   self.touxiang=JSON.parse(ret.data).fileUrl
			                  self.upimg()
							},
						});
						//#endif	
							
			
				
		},
		upimg(){
			var that=this
			this.$http
				.post({
					url: '/api/updateUserAvatar',
					data:{
						'url': this.touxiang
					}
				})
				.then(res => {
					if(res.code==200){
						uni.showToast({
							title: '修改成功',
							icon: 'none'
						});
					    // that.touxiang=that.touxiang.replace('temporary/', "");
					}
				});
		},
		logout(){
			
			uni.removeStorageSync('Cookie');
			uni.redirectTo({
				url:'/pages/index/login'
			})
		},
		save(){
			
			if(this.user.sms_mobile!=this.tongzhi_phone){
				this.$http
					.post({
						url: '/mapi/user/change_sms_mobile',
						data:{
							mobile:this.tongzhi_phone
						}
					})
					.then(res => {
						if(res.code==0){
							
							this.user.sms_mobile=this.tongzhi_phone
							if(this.user.qq==this.qq){
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
								
							}
						}
					});
			}
			if(this.user.qq!=this.qq){

				this.change_qq()
			}
	
		},
		go_zhuxiao(){
			uni.showModal({
				title: '提示',
				content: '确定注销账户？',
				cancelText: "取消", // 取消按钮的文字  
				confirmText: "确认", // 确认按钮的文字  
				showCancel: true, // 是否显示取消按钮，默认为 true
				confirmColor: '#f55850',
				cancelColor: '#39B54A',
				success: (res) => {
				if(res.confirm) {  
					console.log('comfirm') //点击确定之后执行的代码
					this.zhuxiao()
				} else {  
					console.log('cancel') //点击取消之后执行的代码
					}  
				} 
			})
		
		},
		zhuxiao(){
			// console.log('注销')
			this.$http
				.post({
					url: '/mapi/user/del_user'
				})
				.then(res => {
					if(res.code==0){
			            uni.showToast({
			            	title: res.message,
			            	duration: 2000,
			            	icon: 'none'
			            });
			            setTimeout(function(){
			            	uni.reLaunch({
			            		url:'/pages/index/login'
			            	})
			            },500)  
					}
				});
		},
	},
	filters: {
		timeStamp: function(value) {
			if (value == null) {
				return 'null';
			}
			var i = (value + '').length;
			while (i++ < 13) value = value + '0';
			value = Number(value);
			var date = new Date(value);
			//date.setTime(value);
			var month = date.getMonth() + 1;
			var hours = date.getHours();
			if (hours < 10) hours = '0' + hours;
			var minutes = date.getMinutes();
			if (minutes < 10) minutes = '0' + minutes;
			var time = date.getFullYear() + '-' + month + '-' + date.getDate() + ' ' + hours + ':' + minutes;
			return time;
		}
	}
};
</script>

<style>
.head {
	border-bottom: 1px solid #eeeeee;
}
page{
	background-color: #f3f3f3;
}
/* 个人资料 */
.ziliao {
	padding-left: 30rpx;
	padding-right: 30rpx;
	background-color: #ffffff;
}

.ziliao_list {
	display: flex;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid #f5f5f5;
}

.ziliao_list view {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	height: 104rpx;
}

.go {
	width: 8rpx;
	height: 14rpx;
	margin-left: 20rpx;
}

.leftdiv {
	width: 56rpx;
	height: 56rpx;
}

.border_top {
	border-top: 20rpx #f3f3f3 solid;
}

.tuichu {
	/* height: 104rpx; */
	line-height: 104rpx;
	border-top: 20rpx #f3f3f3 solid;
	border-bottom: 20rpx #f3f3f3 solid;
	background-color: #ffffff;
	padding: 0 30rpx;
}
.ziliao_list_right{
	display: flex;
	align-items: center;
}
.ziliao_list_right input{
	text-align: right;
}
.banquan{
	text-align: center;
	margin-top: 70rpx;
	padding-bottom: 100rpx;
	line-height: 56rpx;
}
.banquan_top{
	margin-bottom: 14rpx;
}
	
</style>
